package com.cn.study009;

import java.util.Random;
import java.util.Scanner;

/**
 * @author lw
 * @ClassName Demo004.java
 * @Description
 * @createTime 2023年05月14日
 */
public class Demo004 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = null;           //判断是否继续
        String user = null;          //用户名
        String password = null;       //密码
        int max = 9999;
        int min = 1000;
        boolean mark = false;    //判断注册是否成功
        boolean mark1 = false;    //判断登录是否成功
        do {
            System.out.println("*****欢迎进入奖客富翁系统*****");
            System.out.println("\t\t1.注册");
            System.out.println("\t\t2.登录");
            System.out.println("\t\t3.抽奖");
            System.out.println("*****************************");
            System.out.print("请选择菜单：");
            int n = sc.nextInt();
            switch (n) {
                case 1:
                    System.out.println("奖客富翁系统> 注册");
                    System.out.println("请填写个人注册信息：");
                    System.out.print("用户名：");
                    user = sc.next();
                    System.out.print("密码：");
                    password = sc.next();
                    if (user != null && password != null) {
                        mark = true;
                        System.out.println("注册成功，请记住您的会员卡号");
//                      int cardNumber = (int) (Math.random() * (max - min)) + min;
                        Random random = new Random();
                        int cardNumber = (int) (random.nextDouble() * (max - min)) + min;
                        System.out.println("用户名\t\t密码\t\t会员卡号");
                        System.out.println(user + "\t\t" + password + "\t\t" + cardNumber);
                    } else {
                        System.out.println("注册失败！");
                        mark = false;
                    }
                    break;
                case 2:
                    System.out.println("奖客富翁系统> 登录");
                    if (mark == true) {
                        for (int i = 1; i <= 3; i++) {
                            System.out.print("请输入用户名：");
                            String u = sc.next();
                            System.out.print("请输入密码：");
                            String p = sc.next();
                            if (u.equals(user) && p.equals(password)) {
                                System.out.println("欢迎您，" + user);
                                mark1 = true;
                                break;
                            } else if (i < 3) {
                                System.out.println("用户名或密码错误，请重新输入：");
                            } else {
                                System.out.println("超过三次，登录失败！");
                            }
                        }
                    } else {
                        System.out.println("请先注册！");
                        mark1 = false;
                    }
                    break;
                case 3:
                    if (mark1 == true) {
                        System.out.println("奖客富翁系统> 抽奖");
                        System.out.print("请输入您的卡号：");
                        int number = 0;
                        if (sc.hasNextInt()) {
                            number = sc.nextInt();
                        } else {
                            System.out.println("输入错误！请输入数字");
                        }
                        int[] cn = new int[5];
                        for (int i = 0; i < cn.length; i++) {
                            cn[i] = (int) (Math.random() * (max - min)) + min;
                        }
                        System.out.print("本日的幸运数字为：");
                        for (int num : cn) {
                            System.out.print(num + " ");
                        }
                        for (int i = 0; i < cn.length; i++) {
                            if (number == cn[i]) {
                                System.out.println("您是本日幸运会员！");
                            } else if (i == cn.length - 1) {
                                System.out.println("\n抱歉！您不是本日幸运会员！");
                            }
                        }
                    } else {
                        System.out.println("请先登录！");
                    }

                    break;
                default:
                    System.out.println("您的输入有误！");
            }
            System.out.print("继续吗？(y/n)");
            str = sc.next();
        } while (str.equals("y"));

        System.out.println("\n系统退出，谢谢使用！");
    }
}
